<html>
<head><meta charset="utf-8"><title>repeat expressions · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html">repeat expressions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212731157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212731157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212731157">(Oct 08 2020 at 18:29)</a>:</h4>
<p><code>min_const_generics</code> forbids params in anonymous constants during name resolution.</p>
<p>We already have code working on stable which uses params in repeat expression which is currently linted against (<a href="https://github.com/rust-lang/rust/issues/74595">#74595</a>)</p>



<a name="212731280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212731280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212731280">(Oct 08 2020 at 18:30)</a>:</h4>
<p>afaict lifetimes are currently still completely unusable as it seems to always cause an ICE (please test this for yourself). For example</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">wow</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="nc">where</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="p">()</span>: <span class="nb">Sized</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">3</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">what</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">wow</span>::<span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">()];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212731447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212731447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212731447">(Oct 08 2020 at 18:31)</a>:</h4>
<p>nm, only early bound lifetimes break, late bound lifetimes are already supported</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">what</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="p">()</span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">a</span> <span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="mi">3</span><span class="w"></span>
<span class="w">    </span><span class="p">}];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212731902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212731902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212731902">(Oct 08 2020 at 18:34)</a>:</h4>
<p>so I personally feel that it's fine to "just" forbid lifetimes here, even if it breaks the second example here, as the current support is far from ideal and afaict never actually useful (It should always just be possible to replace <code>'a</code> with <code>'static</code>)</p>



<a name="212732176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212732176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212732176">(Oct 08 2020 at 18:37)</a>:</h4>
<p>I am not so sure about type and const parameters <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> we may want to only forbid them in types but lift the restrictions for repeat expressions to not break stable code</p>



<a name="212732781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212732781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212732781">(Oct 08 2020 at 18:42)</a>:</h4>
<p>I am still not too happy about breaking the following and think that doing so to slightly simplify <code>min_const_generics</code> is not worth it</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">N</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212732881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212732881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212732881">(Oct 08 2020 at 18:43)</a>:</h4>
<p>So to summarize, I think that with <code>min_const_generics</code>,  we should</p>



<a name="212733116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212733116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212733116">(Oct 08 2020 at 18:45)</a>:</h4>
<ul>
<li>completely forbid lifetimes in anonymous constants which fixes ICE for early bound lifetimes and breaks code currently compiling on stable for late bound lifetimes (<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=2f13bc141295e2cf606b04cf8235c5ac">playground</a>)</li>
</ul>



<a name="212733328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212733328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212733328">(Oct 08 2020 at 18:46)</a>:</h4>
<ul>
<li>forbid type parameters in anonymous constants if they are used inside of types, fixing ICE and weird error messages, but keep allowing type parameters in repeat expressions while emitting the <code>const_evaluatable_unchecked</code> future compat lint, not breaking any code compiling on stable (that I know of)</li>
</ul>



<a name="212733699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212733699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212733699">(Oct 08 2020 at 18:50)</a>:</h4>
<ul>
<li>only allow const params by themselves (<code>[u8; N]</code> and  <code>[0; N]</code>) in both repeat expressions and types. Meaning that const params in more complex expressions always result in a compile error.</li>
</ul>



<a name="212806938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212806938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212806938">(Oct 09 2020 at 10:24)</a>:</h4>
<p>We already forbid such lifetimes, right?</p>



<a name="212807149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212807149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212807149">(Oct 09 2020 at 10:27)</a>:</h4>
<p>(I need to think about these examples a bit more. I'll reply properly later.)</p>



<a name="212807622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212807622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212807622">(Oct 09 2020 at 10:33)</a>:</h4>
<p>yeah, the only change from the current <code>min_const_generics</code> impl will be to allow type params in repeat expressions, the rest is already implemented</p>



<a name="212807732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/212807732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#212807732">(Oct 09 2020 at 10:34)</a>:</h4>
<p>I think we never previously explicitly stated that late bound lifetimes currently work on stable, so I wanted to at least acknowledge that we have a breaking change here</p>



<a name="213697283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213697283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213697283">(Oct 18 2020 at 09:11)</a>:</h4>
<p>I would like to go ahead with the loosening of ty params in repeat expressions and then be done with this issue, <span class="user-mention" data-user-id="121053">@varkor</span> did you have the time to look more deeply into this?</p>



<a name="213725952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213725952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213725952">(Oct 18 2020 at 21:08)</a>:</h4>
<p>Are there any concerns with permitting generic parameters in repeat expressions, other than inconsistency with other anonymous constants?</p>



<a name="213725962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213725962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213725962">(Oct 18 2020 at 21:08)</a>:</h4>
<p>Sorry, it's been hectic since then, and I haven't thought about it in detail, but I would imagine that is fine if not.</p>



<a name="213762167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213762167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213762167">(Oct 19 2020 at 09:42)</a>:</h4>
<p>not really, we always emit a future compat lint in that case and this will mostly keep the behavior we have on stable atm</p>



<a name="213762397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213762397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213762397">(Oct 19 2020 at 09:45)</a>:</h4>
<p>this keeps the behavior of</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![allow(dead_code)]</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;*</span><span class="k">mut</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span><span class="p">()];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">ASSOC</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="213762423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213762423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213762423">(Oct 19 2020 at 09:45)</a>:</h4>
<p>which compiles on nightly with</p>
<div class="codehilite"><pre><span></span><code>warning: cannot use constants which depend on generic parameters in types
 --&gt; src/lib.rs:4:9
  |
4 |     [0; std::mem::size_of::&lt;*mut T&gt;()];
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(const_evaluatable_unchecked)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #76200 &lt;https://github.com/rust-lang/rust/issues/76200&gt;

warning: cannot use constants which depend on generic parameters in types
  --&gt; src/lib.rs:13:13
   |
13 |         [0; Self::ASSOC];
   |             ^^^^^^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #76200 &lt;https://github.com/rust-lang/rust/issues/76200&gt;

warning: 2 warnings emitted
</code></pre></div>



<a name="213766187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/213766187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#213766187">(Oct 19 2020 at 10:25)</a>:</h4>
<p>Sounds good to me <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="214158424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214158424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214158424">(Oct 22 2020 at 08:43)</a>:</h4>
<p>implemented in <a href="https://github.com/rust-lang/rust/issues/78224">#78224</a></p>



<a name="214357021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357021">(Oct 23 2020 at 19:38)</a>:</h4>
<p>PANIC!<br>
<a href="https://github.com/rust-lang/rust/issues/78224">#78224</a> will extend the <code>const_evaluatable_unchecked</code> future compat lint to <code>Self</code> types containing const params</p>



<a name="214357086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357086">(Oct 23 2020 at 19:39)</a>:</h4>
<p>for example</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">ASSOC</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="214357158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357158">(Oct 23 2020 at 19:40)</a>:</h4>
<p>this is not possible on stable (obviously) but will be a future compat lint afterwards</p>



<a name="214357189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357189">(Oct 23 2020 at 19:40)</a>:</h4>
<p>I think that's something we can live with, should I just add it as a test to <a href="https://github.com/rust-lang/rust/issues/78224">#78224</a> <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="214357437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357437">(Oct 23 2020 at 19:43)</a>:</h4>
<p>But that lint is incorrect, no? It's not an issue to use <code>Self::ASSOC</code>, because it cannot be generic.</p>



<a name="214357584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357584">(Oct 23 2020 at 19:45)</a>:</h4>
<p>well, somewhat</p>



<a name="214357614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357614">(Oct 23 2020 at 19:45)</a>:</h4>
<p>we probably do want to allow that</p>



<a name="214357788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357788">(Oct 23 2020 at 19:47)</a>:</h4>
<p>I don't see associated consts being a problem, because if there is an issue using them, they'll already trigger an error where they are declared.</p>



<a name="214357910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214357910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214357910">(Oct 23 2020 at 19:49)</a>:</h4>
<p>there is stuff like this</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>

<span class="c1">// works</span>
<span class="k">fn</span> <span class="nf">test1</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">T</span>::<span class="n">ASSOC</span><span class="p">];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// does not work, because of how trait resolution currently works</span>
<span class="k">fn</span> <span class="nf">test2</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Foo</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">T</span>::<span class="n">ASSOC</span><span class="p">];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="214358056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214358056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214358056">(Oct 23 2020 at 19:50)</a>:</h4>
<p>but allowing associated types for inherent impls is probably something we want</p>



<a name="214358123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214358123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214358123">(Oct 23 2020 at 19:51)</a>:</h4>
<p>though I can't say for sure if that also won't break down for some weird inputs</p>



<a name="214358207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214358207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214358207">(Oct 23 2020 at 19:52)</a>:</h4>
<p>I don't think it's a huge issue if there are some rare false positives, considering we hope to fix it before too long anyway.</p>



<a name="214358225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214358225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214358225">(Oct 23 2020 at 19:52)</a>:</h4>
<p>what's a false positive here?</p>



<a name="214358251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214358251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214358251">(Oct 23 2020 at 19:53)</a>:</h4>
<p>code that works even though it shouldn't or code we lint even though it should work</p>



<a name="214358688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/repeat%20expressions/near/214358688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/repeat.20expressions.html#214358688">(Oct 23 2020 at 19:57)</a>:</h4>
<p>A lint even though it should work.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>